#ifndef _SE_RENDERCONTEXT_
#define _SE_RENDERCONTEXT_

#include "Render/Shader.h"
#include "Render/Buffers.h"
#include "Render/Texture.h"

namespace SE
{
	struct RenderVertex2D
	{
		Vector2f    position;
		Vector2f    texCoord;
		Vector4f    color;
	};

	struct RenderVertex3D
	{
		Vector3f    position;
		Vector2f    texCoord;
		Vector4f    color;
		Vector3f    normal;
		Matrix4f	transform;
	};

	struct RenderVertex
	{
		Vector3f    position;
		Vector3f    normal;
		Vector4f    color;
		Vector2f    texCoord;
		Matrix4f	transform;

		Float       texIndex;
		Float       tilingFactor;

		// Editor-only
		I32         entityID;
	};

	struct CameraData
	{
		Vector3f	cameraPosition;
		Matrix4f	viewMatrix;
		Matrix4f	projectionMatrix;
	};

	struct RenderContext
	{
		Ref<FrameBuffer>		background;

		// Camera data.
		CameraData				cameraData;

		// Render statistics.
		U32						drawCalls = 0;


		//-------------------------------------------------------------------------------------------------------------------------
		/* Triangle */
		static constexpr U32	MaxTriangles = 10000;
		using TriangleVertices	= Array<RenderVertex, MaxTriangles * 3>;

		Ref<Shader>				triangleShader;
		Ref<VertexArray>		triangleVAO;
		Ref<VertexBuffer>		triangleVBO;
		U32						triangleIndex;
		TriangleVertices		triangleVertices;
		//-------------------------------------------------------------------------------------------------------------------------


		//-------------------------------------------------------------------------------------------------------------------------
		/* Quad */
		static constexpr U32	MaxQuads = 10000;
		static constexpr RenderVertex2D DefaultRenderVertices2D[4] =
		{
			{ { -0.5f, -0.5f }, { 0.0f, 0.0f } , { 1.0f, 1.0f, 1.0f, 1.0f } },
			{ {  0.5f, -0.5f }, { 0.1f, 0.0f } , { 1.0f, 1.0f, 1.0f, 1.0f } },
			{ {  0.5f,  0.5f }, { 0.1f, 1.0f } , { 1.0f, 1.0f, 1.0f, 1.0f } },
			{ { -0.5f,  0.5f }, { 0.0f, 1.0f } , { 1.0f, 1.0f, 1.0f, 1.0f } }
		};
		using QuadVertices	= Array<RenderVertex, MaxQuads * 4>;
		using QuadIndices	= Array<U32, MaxQuads * 6>;

		Ref<Shader>				quadShader;
		Ref<VertexArray>		quadVAO;
		Ref<VertexBuffer>		quadVBO;
		U32						quadIndex;
		QuadVertices			quadVertices;
		QuadIndices				quadIndices;
		//-------------------------------------------------------------------------------------------------------------------------


		//-------------------------------------------------------------------------------------------------------------------------
		/* Texture */
		static constexpr U32	MaxTextureSlots = 32;
		using TextureSlots = Array< Ref<Texture>, MaxTextureSlots >;

		Ref<Texture>			whiteTexture;
		U32						textureSlotIndex = 1; // 0 is white texture.
		TextureSlots			textureSlots;
		//-------------------------------------------------------------------------------------------------------------------------
	};
} // !namespace SE

#endif // !_SE_RENDERCONTEXT_